<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Usersrecharges extends Model
{
    protected $table = 'users_recharges';
    protected $primaryKey = 'id';
    public static $status = ['', '待支付', '成功', '失败'];
    public static $payment = ['', '支付宝', '微信'];

    public static function usersRechargesInsert($users_id, $order_id, $money, $payment)
    {
        return self::insert([
            'users_id'   => $users_id,
            'order_id'   => $order_id,
            'money'      => $money,
            'payment'    => $payment,
            'created_at' => time(),
        ]);
    }

    public static function insertAlipayData($data)
    {
        return self::insert($data);
    }

    public static function usersRechargesById($order_id)
    {
        return self::where('order_id', $order_id)->first();
    }

    public static function usersRechargesUpdateByOrderId($order_id, $data)
    {
        return self::where('order_id', $order_id)->update($data);
    }

    public static function rechargesLists($users_id)
    {
        $recharges = self::select('users_recharges.*','users.nike','users.avatar')
            ->leftjoin('users', 'users.id', '=', 'users_recharges.users_id');
        if (!empty($users_id)) $recharges->where("users_recharges.users_id", $users_id);
        return $recharges = $recharges->orderBy('users_recharges.id', 'desc')->paginate(25);

    }
}
